package com.good.cm.utils;

import com.good.cm.exception.ParamsException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import java.text.ParseException;
import java.util.Date;

public class AssertUtil {
    public static void isTrue(Boolean flag,String msg){

    if (flag)
        throw new ParamsException(msg);
    }

    /**
     * 字符串转int
     * @param str
     * @return
     */
    public static int  stringToInt(String str){
        int foo;
        if (StringUtils.isBlank(str))
            return 0;
        try {
            foo = Integer.parseInt(str);
        }
        catch (NumberFormatException e) {
            foo = 0;
        }
        return foo;
    }
    public static Date TransDate(String date){
        //
        String format="yyyy-MM-dd HH:mm:ss";
        try {
          return   DateUtils.parseDate(date,format);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Date();
    }
}
